var smallreunion;
if(!smallreunion) smallreunion = {};
smallreunion.func = {};


$(function() {
  $("#readMoreButton").click(function() {smallreunion.func.readMore(); });
});

smallreunion.func.readMore = function() {

  var tmpl = _.template(
        "<div class=\"twitter-bbspost\">" +
          "<div class=\"twitter-profile-image\">" +
            "<a href=\"#\">" +
              "<img height=\"48\" width=\"48\" class=\"thumbnail\" src=\"<%-twitterProfileImageUrl%>\" alt=\"twitterProfileImage\">" +
            "</a>" +
          "</div>" +
          "<div class=\"twitter-bbspost-body\">" +
            "<div class=\"twitter-screen-name\">" +
              "<a href=\"http://twitter.com/<%-twitterScreenName%>\" target=\"_blank\">" +
                "<%-twitterScreenName%>" +
              "</a>" +
            "</div>" +
            "<div class=\"twitter-name\">" +
              "<%-twitterName%>" +
            "</div>" +
            "<div class=\"twitter-entrydate\">" +
              "<%-entryDate%>" +
            "</div>" +
            "<div class=\"twitter-content\">" +
              "<%=content%>" +
            "</div>" +
            "<div class=\"twitter-tools\">" +
              "<a href=\"#\">Reply</a>" +
              "<a href=\"#\" >Delete</a>" +
            "</div>" +
          "</div>" +
        "</div>");

  $.get("/ajax/bbs.json", {
        cursor: $("#cursor").val(),},
    function(data) {
        switch (data.status) {
            case "OK":
              $("#cursor").val(data.cursor);
              _.each(data.bbsPostList, function(n){
                var html = tmpl({ twitterProfileImageUrl:n.twitterProfileImageUrl,
                      twitterScreenName:n.twitterScreenName,
                      twitterName:n.twitterName,
                      entryDate:n.viewEntryDate,
                      content:n.viewContent});
                $("#twitter-bbspost-list").append(html);
              });
              if (!data.hasNext) {
                $(".actions").hide();
              }
              break;
            case "NG":
              break;
        }
    });
}